package com.wangdao.mall.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @Author:HaiyangTian
 * @Description:
 * @Date: Created in 12:18 2020/5/2
 * @Modified By:
 */
@WebListener
public class ApplicationListener implements ServletContextListener {
    //应用启动就会执行，用来读取加载配置文件中的域名端口号
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        InputStream inputStream = ApplicationListener.class.getClassLoader().getResourceAsStream("application.properties");
        Properties properties = new Properties();
        try {
            properties.load(inputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
        String domain = properties.getProperty("domain");
        servletContextEvent.getServletContext().setAttribute("domain",domain);
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }
}
